package fitness;

import java.io.Serializable;

import optimizers.ganeat.jankenpon.ConstantsJankenpon;

public class EloRecord implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public static enum Result {
		VICTORY, DRAW, DEFEAT
	}
	
	public double opponentElo;
	public int[] iplayed;
	public int[] uplayed;
	public Result victory;
	
	public EloRecord(double opponentElo, int[] iplayed, int[] uplayed, Result victory){
		this.opponentElo = opponentElo;
		this.iplayed = iplayed;
		this.uplayed = uplayed;
		this.victory = victory;
	}
	
	public double recordModifier(){
		double mod = 0.0;
		for(int i=0; i< iplayed.length; i++){
			if(iplayed[i] == (uplayed[i] % 3 + 1) || (uplayed[i] == -1 && iplayed[i] != -1)){
				mod += EloResult.victoryAdjust / (double) ConstantsJankenpon.rounds;
			} else if(uplayed[i] == (iplayed[i] % 3 + 1) || iplayed[i] == -1){
				mod -= EloResult.victoryAdjust / (double) ConstantsJankenpon.rounds;
			}
		}
		return mod;
	}
	
	public String toString(){
		return ""+opponentElo;
	}

	public boolean isDynamic() {
		int preva = iplayed[0];
		int prevb = uplayed[0];
		for(int i = 1; i< iplayed.length; i++){
			if(iplayed[i-1] != iplayed[i] || uplayed[i-1] != uplayed[i]){
				return true;
			}
		}
		return false;
	}
	
}
